/**
 * Algorithm for Reliable Multicast (from Coulouris, Dollimore, and Kindberg, Distributed Systems Concepts and Design, 4th ed)
 *
 *	Given: reliable one-to-one send
 *
 *	Basic Multicast (B-multicast):
 *		To B-multicast(group, message): for each process p \in group, send(p, message)
 *		On receive(m) at p: B-deliver(message) at p.
 *
 * 	Reliable Multicast (R-Multicast):
 *		On initialization: Received := \{\};
 *
 *		For process p to R-multicast message m to group g
 *			B-multicast(g, m); // p \in g is included as a destination
 *
 *		On B-deliver(m) at process q with g = group(m)
 *			if (m \notin Received)
 *			then
 *				Received := Received \cup \{m\};
 *				if (q \neq p) then B-multicast(g, m); end if
 *				R-deliver m;
 *			end if
 */

#include "multicast.h"

void basic_multicast(struct sockaddr_in* group, int size, msg_clksync* msg) {
	int i;

	for (i = 0; i < size; i++) {
		queue_send(msg, sizeof(msg_clksync), group[i]);
		printf("Sent %d\n", i);
	}
}

void reliable_multicast(struct sockaddr_in* group, int size, msg_clksync* msg) {
	int i;

	//todo: add self to group (malloc some space, add this node; probably need to copy the group parameter locally to one that is one entry larger for memory safety)

	for (i = 0; i < size; i++) {
		basic_multicast(group, size, msg);
	}
}
